package com.adkfp.action;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.adkfp.utils.JsonUtil;
import com.adkfp.bean.LwsNetDoorBean;
import com.adkfp.service.ILwsNetDoorService;

/**
 * class name:LwsNetDoorAction <BR>
 * class description: LwsNetDoor表的增删改查 <BR>
 * Remark: <BR>
 * @version 1.00 2019年01月03日
 * @author JACK)jackwei
 */
@Controller
@RequestMapping("lwsNetDoor")
public class LwsNetDoorAction {
	@Resource(name="lwsNetDoorService")
	private ILwsNetDoorService lwsNetDoorService;

  /**
 	* Method name: selectAll <BR>
 	* Description: 查询所有记录 <BR>
 	* Remark: <BR>
 	* @param bean
 	* @return  Object<BR>
 	*/
	@RequestMapping("selectAll")
	@ResponseBody
	public Object selectAll(LwsNetDoorBean bean) {
		List<LwsNetDoorBean> list = new ArrayList<>();
		list = lwsNetDoorService.findByCondition(bean);
		long count = lwsNetDoorService.findByConditionCount(bean);
		
		return list;
	}
	
	/**
	 * Method name: index <BR>
	 * Description: 转发到页面 <BR>
	 * Remark: <BR>
	 * @return  String<BR>
	 */
	@RequestMapping("index")
	public String index() {
		return "lwsNetDoor/lwsNetDoorIndex";
	}
	
	/**
	 * Method name: options <BR>
	 * Description: LwsNetDoor表的增删改 <BR>
	 * Remark: <BR>
	 * @param request
	 * @param response
	 * @return  String<BR>
	 */
	@RequestMapping("options")
	@ResponseBody
	public String options(@RequestParam("op")String op, @RequestParam("data")String data) {
		String f = "";
		
		switch (op) {
			case "add":
				if(data!=null&&!data.equals("")) {
					List<LwsNetDoorBean> list = JsonUtil.getList4Json(data, LwsNetDoorBean.class);
					for (LwsNetDoorBean bean : list) {
						lwsNetDoorService.insert(bean);
					}
					f = "增加成功";
				}
				break;
			case "del":
				if(data!=null&&!data.equals("")) {
					List<LwsNetDoorBean> list = JsonUtil.getList4Json(data, LwsNetDoorBean.class);
					for (LwsNetDoorBean bean : list) {
						lwsNetDoorService.delete(bean.getNetGroupID());
					}
					f = "删除成功";
				}
				break;
			case "upd":
				if(data!=null&&!data.equals("")) {
					List<LwsNetDoorBean> list = JsonUtil.getList4Json(data, LwsNetDoorBean.class);
					for (LwsNetDoorBean bean : list) {
						lwsNetDoorService.update(bean);
					}
					f = "更新成功";
				}
				break;
			default:
				break;
		}
		return f;
	}
}